added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / CSFTPDownload / UICredentialsProvider.cs
blob9a3762b27c4a82b84a80e1cc9c38287b599b7977
1 /****************************** Module Header ******************************\
2 * Module Name: UICredentialsProvider.cs
3 * Project: CSFTPDownload
4 * Copyright (c) Microsoft Corporation.
5 *
6 * The Form UICredentialsProvider contains 3 textboxes that accept UserName,
7 * Password and Domain to initialize a NetworkCredential instance.
8 *
9 * This source is subject to the Microsoft Public License.
10 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 * All other rights reserved.
13 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
14 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
16 \***************************************************************************/
18 using System;
19 using System.Net;
20 using System.Windows.Forms;
22 namespace CSFTPDownload
24 public partial class UICredentialsProvider : Form
26 public NetworkCredential Credentials { get; set; }
28 bool useOriginalCredentials = true;
30 public UICredentialsProvider()
31 : this(null)
32 { }
34 public UICredentialsProvider(NetworkCredential credentials)
37 InitializeComponent();
39 this.Credentials = credentials;
41 if (this.Credentials != null)
43 this.tbUserName.Text = this.Credentials.UserName;
44 this.tbDomain.Text = this.Credentials.Domain;
45 this.tbPassword.Text = this.Credentials.Password;
46 useOriginalCredentials = true;
48 else
50 useOriginalCredentials = false;
54 private void btnOK_Click(object sender, EventArgs e)
56 if (!useOriginalCredentials)
58 if (chkAnonymous.Checked)
61 // Use Anonymous Credentials by default.
62 Credentials = new NetworkCredential("Anonymous", "");
64 else if (String.IsNullOrWhiteSpace(tbUserName.Text)
65 || String.IsNullOrWhiteSpace(tbPassword.Text))
67 MessageBox.Show("Please type the user name and password!");
68 return;
70 else
72 Credentials = new NetworkCredential(
73 tbUserName.Text.Trim(),
74 tbPassword.Text,
75 tbDomain.Text.Trim());
78 this.DialogResult = System.Windows.Forms.DialogResult.OK;
82 private void btnCancel_Click(object sender, EventArgs e)
84 this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
87 private void chkAnonymous_CheckedChanged(object sender, EventArgs e)
89 tbDomain.Enabled = !chkAnonymous.Checked;
90 tbPassword.Enabled = !chkAnonymous.Checked;
91 tbUserName.Enabled = !chkAnonymous.Checked;
93 useOriginalCredentials = false;
96 private void tb_TextChanged(object sender, EventArgs e)
98 useOriginalCredentials = false;